package cn.tedu.carehome.foundation.service.impl;

import cn.tedu.carehome.foundation.ex.ServiceException;
import cn.tedu.carehome.foundation.mapper.AssessMapper;
import cn.tedu.carehome.foundation.pojo.dto.AssessAddNewDTO;
import cn.tedu.carehome.foundation.pojo.dto.AssessUpdateDTO;
import cn.tedu.carehome.foundation.pojo.entity.Assess;
import cn.tedu.carehome.foundation.pojo.vo.*;
import cn.tedu.carehome.foundation.service.IAssessService;
import cn.tedu.carehome.foundation.web.ServiceCode;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@Slf4j
public class AssessServiceImpl implements IAssessService {
    @Autowired
    AssessMapper assessMapper;

    @Override
    public void addNew(AssessAddNewDTO assessAddNewDTO) {
        log.debug("开始执行添加能力测试评估业务");
        Assess assess = new Assess();
        BeanUtils.copyProperties(assessAddNewDTO, assess);
        int l = assessMapper.insert(assess);
        if (l != 1) {
            throw new ServiceException(ServiceCode.ERR_UPDATE, "添加床位失败,服务器正忙,请稍后再试！");
        }
        log.debug("添加成功！");
    }

    @Override
    public List<AssessAdminListVO> list() {
        log.debug("开始执行查询【床位】业务");
        return assessMapper.list();
    }



    @Override
    public void deleteByid(Long id) {
        log.debug("开始执行【能力评估业务】业务");
        assessMapper.deleteByid(id);
        log.debug("删除成功！");
    }


    @Override
    public AssessAdminStandardVO getStandardByid(Long id) {
        log.debug("开始执行【根据id查询】业务");
        AssessAdminStandardVO assessAdminStandardVO = assessMapper.getStandardByid(id);
        if (assessAdminStandardVO == null) {
            throw new ServiceException(ServiceCode.ERR_NOT_FOUND, "查询失败,找不到此信息");
        }
        log.debug("查询成功，数据为{}", assessAdminStandardVO);
        return assessAdminStandardVO;
    }


}

